﻿#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
using namespace std;

class Person
{
	public :
	// 进⼊校园/图书馆/实验室刷⼆维码等⾝份认证
	void identity()
	{
		cout << "void identity()" << _name << endl;
	}
protected:
	string _name = "张三"; // 姓名
	string _address; // 地址
	string _tel; // 电话
	int _age = 18; // 年龄
};

class Student : public Person
{ public :
// 学习
	void study()
	{
		// ...
	}
	protected:
	int _stuid; // 学号
};
class Teacher : public Person
{
	public :
	// 授课
	void teaching()
	{
		//...
	}
protected:
	string title; // 职称
};

int main()
{
	Student s;
	Teacher t;
	s.identity();
	t.identity();
	return 0;
}

#include <vector>

namespace bit
{
	//template<class T>
	//class vector
	//{};
	// stack和vector的关系，既符合is-a，也符合has-a
	template<class T>
	class stack : public std::vector<T>
	{
		public :
		void push(const T& x)
		{
			// 基类是类模板时，需要指定⼀下类域，
			// 否则编译报错:error C3861: “push_back”: 找不到标识符
			// 因为stack<int>实例化时，也实例化vector<int>了
			// 但是模版是按需实例化，push_back等成员函数未实例化，所以找不到

				vector<T>::push_back(x);

			//push_back(x);
		} 
		void pop()
		{
			vector<T>::pop_back();
		} 
		const T& top()
		{
			return vector<T>::back();
		} 
		bool empty()
		{
			return vector<T>::empty();
		}
	};
}

int main()
{
	bit::stack<int> st;
	st.push(1);
	st.push(2);
	st.push(3);
	while (!st.empty())
	{
		cout << st.top() << " ";
		st.pop();
	} 
	return 0;
}





class Person
{
	protected :
	string _name; // 姓名
	string _sex; // 性别
	int _age; // 年龄
};
class Student : public Person
{
	public :
	int _No; // 学号
};
int main()
{
	Student sobj;
	// 1.派⽣类对象可以赋值给基类的指针/引⽤
	Person* pp = &sobj;
	Person& rp = sobj;
	// ⽣类对象可以赋值给基类的对象是通过调⽤后⾯会讲解的基类的拷⻉构造完成的
	Person pobj = sobj;
	//2.基类对象不能赋值给派⽣类对象，这⾥会编译报错
	//sobj = pobj;
	return 0;
}


class Person
{
	protected :
	string _name = "小李子"; // 姓名
	int _num = 111; // ⾝份证号
};
class Student : public Person
{
	public :
	void Print()
	{
		cout << " 姓名:" << _name << endl;
		cout << " 身份证号:" << Person::_num << endl;
		cout << " 学号:" << _num << endl;
	}
protected:
	int _num = 999; // 学号
};
int main()
{
	Student s1;
	s1.Print();
	return 0;
};






class Person
{
	public :
	Person(const char* name = "peter")
		: _name(name)
	{
		cout << "Person()" << endl;
	} 
	Person(const Person& p)
		: _name(p._name)
	{
		cout << "Person(const Person& p)" << endl;
	} 
	Person& operator=(const Person& p)
	{
		cout << "Person operator=(const Person& p)" << endl;
		if (this != &p)
			_name = p._name;
		return *this;
	} 
	~Person()
	{
		cout << "~Person()" << endl;
	}
protected:
	string _name; // 姓名
};


class Student : public Person
{
	public :
	Student(const char* name, int num)
		: Person(name)
		, _num(num)
	{
		cout << "Student()" << endl;
	} 
	Student(const Student& s)
		: Person(s)
		, _num(s._num)
	{
		cout << "Student(const Student& s)" << endl;
	} 
	Student& operator = (const Student& s)
	{
		cout << "Student& operator= (const Student& s)" << endl;
		if (this != &s)
			{
			// 构成隐藏，所以需要显⽰调⽤
			Person::operator =(s);
			_num = s._num;
		} 
		return* this;
	} ~
		Student()
	{
		cout << "~Student()" << endl;
	}
protected:
	int _num; //学号
};

int main()
{
	Student s1("jack", 18);
	Student s2(s1);
	Student s3("rose", 17);
	s1 = s3;
	return 0;
}

class Person
{
public:
	Person(const char* name )
		: _name(name)
	{
		cout << "Person()" << endl;
	}
	Person(const Person& p)
		: _name(p._name)
	{
		cout << "Person(const Person& p)" << endl;
	}
	Person& operator=(const Person& p)
	{
		cout << "Person operator=(const Person& p)" << endl;
		if (this != &p)
			_name = p._name;
		return *this;
	}
	~Person()
	{
		cout << "~Person()" << endl;
	}
protected:
	string _name; // 姓名
};


class Student : public Person
{
public:
	Student(const char* name, int num, const char* address)
		: Person(name)
		, _num(num)
		,_address(address)
	{
		cout << "Student()" << endl;
	}
	Student(const Student& s)
		: Person(s)
		, _num(s._num)
	{
		cout << "Student(const Student& s)" << endl;
	}
	Student& operator = (const Student& s)
	{
		cout << "Student& operator= (const Student& s)" << endl;
		if (this != &s)
		{
			 构成隐藏，所以需要显⽰调⽤
			Person::operator =(s);
			_num = s._num;
		}
		return*this;
	} 
	~Student()
	{
		cout << "~Student()" << endl;
	}
protected:
	int _num = 1; //学号
	string _address = "成都市新都区";
};
int main()
{
	Student s1("jack", 18,"成都市");
	
	
	return 0;
}